using UnityEngine;

//这段代码是一个Hand类，用于处理角色的手部动画。
public class Hand : MonoBehaviour
{
    public bool isLeft; // 是否是左手
    public SpriteRenderer spriter; // 手的sprite renderer组件
    SpriteRenderer player; // 玩家的sprite renderer组件
    Quaternion rightRot = Quaternion.Euler(0, 0, -25);
    Quaternion rightRotReverse = Quaternion.Euler(0, 0, 25);

    Vector3 leftPos = new Vector3(0.4f, -0.2f, 0);
    Vector3 leftPosReverse = new Vector3(0.1f, -0.2f, 0);

    void Awake()
    {
        player = GetComponentsInParent<SpriteRenderer>()[1]; // 获取玩家的sprite renderer组件
    }

    void LateUpdate()
    {
        bool isReverse = player.flipX; // 判断玩家是否水平翻转

        if (isLeft)
        {
            // 处理左手
            spriter.flipX = isReverse; 
            spriter.sortingOrder = isReverse ? 6 : 4;
            transform.localPosition = !isReverse ? leftPos : leftPosReverse;
        }
        else
        {
            // 处理右手
            transform.localRotation = isReverse ? rightRotReverse : rightRot;
            spriter.flipX = isReverse;
            spriter.sortingOrder = isReverse ? 4 : 6;
        }
    }
}
